# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html
import os

class CsdnlgPipeline(object):
    def process_item(self, item, spider):
        print(item)
        #判断并生成存储路径
        path1='D:/csdn/course/'
        if os.path.exists(path1):
            pass
        else:
            os.mkdir(path1)
        #创建txt文件并写入内容
        filepath='D:/csdn/course/'+str(item['courseTitle'])+'.txt'
        file=open(filepath,'w')
        k='课程名:'+str(item['courseTitle'])+'\n'+'价格:'+str(item['price'])+'\n'+'课程数:'+str(item['courseNum'])+'\n'+'学生数:'+str(item['stuNum'])
        #print('k',k)
        file.write(k)
        file.close()
        return item
